const fs = require('fs')
const data = require('./src/assets/IPC.json')

const newData = { categories: [], nodes: [], links: [] }

newData.links = data.links.map(item => {
  return {
    'id': item.id,
    'source': item.source,
    'target': item.target,
  }
})
data.nodes.forEach(item => {
  newData.nodes.push({
    'id': item.id,
    'name': item.id,
    'symbolSize': item.symbolSize,
    'x': item.x,
    'y': item.y,
    'category': item.attributes.modularity_class,
    'indegree': item.attributes.indegree,
    'outdegree': item.attributes.outdegree,
  })
  const modularity_class = item.attributes.modularity_class
  const modularity = newData.categories.find(item => item.name === modularity_class)

  if (!modularity) {
    newData.categories.push({ name: modularity_class })
  }
})
console.log(newData.links.length, newData.nodes.length)
// newData.nodes = newData.nodes.slice(0, 500)
// newData.links = newData.links.slice(0, 10000)

fs.writeFileSync('./src/assets/test.json', JSON.stringify(newData, null, 2))
